home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_130 / hp / hp_conversions.include < prev    next >
Text File  |  1992-05-06  |  8KB  |  335 lines

  1. /*-------------------------------------------*/
  2. /*                                           */
  3. /*   Filename:  hp_conversions.include       */
  4. /*                                           */
  5. /*   Contains the C source code for the      */
  6. /*   routines DisplayFloatXY, DisplayIntXY,  */
  7. /*   InkeyIsNumeric, ContinueNumEntry,       */
  8. /*   CommenceNumEntry and PushX.  These      */
  9. /*   are used by the routine hp.c.           */
  10. /*                                           */
  11. /*-------------------------------------------*/
  12.  
  13. DisplayFloatXY()
  14. {
  15.  int i, xpoint, xsign, ypoint, ysign;
  16.  char temp_string[34], *tsptr;
  17.  
  18.  xptr = &xstr[9];
  19.  yptr = &ystr[9];
  20.  
  21.  tsptr = &temp_string[9];
  22.  
  23.  /* Convert floating point to ASCII      */
  24.  tsptr = ecvt( x, 12, &xpoint, &xsign );
  25.  for ( i = 20; i >= 10; i--) xstr[i+1] = *(tsptr + i - 9);
  26.  xstr[9] = *tsptr;
  27.  
  28.  tsptr = ecvt( y, 12, &ypoint, &ysign );
  29.  for ( i = 20; i >= 10; i--) ystr[i+1] = *(tsptr + i - 9);
  30.  ystr[9] = *tsptr;
  31.  
  32.  /* Prevents the display of  0.0 E-1  */
  33.  if ( x == 0.0 )   {
  34.     xpoint  =  1 ;
  35.     xstr[9] = '0'; }
  36.  
  37.  if ( y == 0.0 )   {
  38.     ypoint  =  1 ;
  39.     ystr[9] = '0'; }
  40.  
  41.  xstr[22] = ' ';
  42.  ystr[22] = ' ';
  43.  xstr[23] = ' ';
  44.  ystr[23] = ' ';
  45.  xstr[10] = '.';
  46.  ystr[10] = '.';
  47.  xstr[ 8] = ' ';
  48.  ystr[ 8] = ' ';
  49.  
  50.  if ( xsign != 0 ) xstr[8] = '-';
  51.  if ( ysign != 0 ) ystr[8] = '-';
  52.  
  53.  
  54.  if ( xpoint < 1 )
  55.     xstr[24] = '-';
  56.  else
  57.     xstr[24] = ' ';
  58.  
  59.  xpoint = abs( xpoint - 1 );
  60.  
  61.  xstr[25] = hex_char[ xpoint / 10 ];
  62.  xstr[26] = hex_char[ xpoint % 10 ];
  63.  xstr[27] = 0;
  64.  
  65.  
  66.  if ( ypoint < 1 )
  67.     ystr[24] = '-';
  68.  else
  69.     ystr[24] = ' ';
  70.  
  71.  ypoint = abs( ypoint - 1 );
  72.  
  73.  ystr[25] = hex_char[ ypoint / 10 ];
  74.  ystr[26] = hex_char[ ypoint % 10 ];
  75.  ystr[27] = 0;
  76.  
  77.   
  78.  
  79.  SetAPen( rp, BLACK );
  80.  SetDrMd( rp, JAM2  );
  81.  
  82.  Move( rp, start_display[ base ], 50);
  83.  Text( rp, &ystr[8], 19 );
  84.  
  85.  Move( rp, start_display[ base ], 59);
  86.  Text( rp, &xstr[8], 19 );
  87.  
  88. }
  89. /*--------------------------------------------------------*/
  90. DisplayIntXY()
  91. {
  92.  unsigned long tempint;
  93.  int j, numbits, next_digit, x_length, y_length, x_shift, y_shift;
  94.  
  95.  if ( base == 10 ) {
  96.    x_length = stci_d( &xstr[0], ix, 12 );
  97.    y_length = stci_d( &ystr[0], iy, 12 );
  98.  
  99.    xstr[display_length[10]] = 0;
  100.    ystr[display_length[10]] = 0;
  101.  
  102.    x_shift = display_length[10] - x_length;
  103.    y_shift = display_length[10] - y_length;
  104.  
  105.    for( j = x_length-1; j >= 0; j--)
  106.      xstr[j + x_shift] = xstr[j];
  107.  
  108.    for( j = y_length-1; j >= 0; j--)
  109.      ystr[j + y_shift] = ystr[j];
  110.  
  111.    for( j = x_shift-1;  j >= 0; j--)
  112.      xstr[j] = ' ';
  113.    for( j = y_shift-1;  j >= 0; j--)
  114.      ystr[j] = ' '; 
  115.                    }
  116.  else              {       /*   Base is power of two   */
  117.  
  118.    if ( base ==  2 ) numbits = 1;
  119.    if ( base ==  8 ) numbits = 3;
  120.    if ( base == 16 ) numbits = 4;
  121.  
  122.    xstr[ display_length[ base ] ] = 0;
  123.    j = display_length[ base ] - 1;
  124.  
  125.    tempint = ix;
  126.  
  127.    while ( tempint != 0 )    {
  128.      next_digit = tempint & bitmask[ numbits ];
  129.      xstr[ j-- ] = hex_char[ next_digit ];
  130.      tempint >>= numbits;  }
  131.  
  132.    if ( ix == 0 )      xstr[j--] = '0';
  133.    while (  j   >= 0 ) xstr[j--] = ' ';
  134.  
  135.    /*  Now repeat the process for y   */
  136.    
  137.    ystr[ display_length[ base ] ] = 0;
  138.    j = display_length[ base ] - 1;
  139.  
  140.    tempint = iy;
  141.  
  142.    while ( tempint != 0 )    {
  143.      next_digit = tempint & bitmask[ numbits ];
  144.      ystr[ j-- ] = hex_char[ next_digit ];
  145.      tempint >>= numbits;  }
  146.  
  147.    if ( iy == 0 )      ystr[j--] = '0';
  148.    while (  j   >= 0 ) ystr[j--] = ' ';
  149.  
  150.    }   /* Base is power of 2  */
  151.     
  152.  
  153.  Move( rp, start_display[ base ], 50);
  154.  Text( rp, &ystr[0], display_length[ base ] );
  155.  
  156.  Move( rp, start_display[ base ], 59);
  157.  Text( rp, &xstr[0], display_length[ base ] );
  158.  
  159. }
  160. /*--------------------------------------------------------*/
  161. BOOL InkeyIsNumeric()
  162. {
  163.   int k;
  164.   if (  inkey == 16 )                  return( TRUE  );
  165.   if ( (inkey == 53 ) && (base > 1) )  return( FALSE );
  166.   if ( (inkey == 53 ) && (entry_in_progress == FALSE))   return( FALSE );
  167.   k = inkey % 4;
  168.   if ( (inkey > 0) && (inkey < 19) && (k != 0) )         return( TRUE );
  169.   if ( (inkey == 49) || (inkey == 50) )   return( TRUE );
  170.   if ( (inkey == 53) || (inkey == 54) )   return( TRUE );
  171.   return( FALSE );
  172. }
  173. /*--------------------------------------------------------*/
  174. ContinueNumEntry()
  175. {
  176.  int  signif_length, flip_pos;
  177.  char flip_val;
  178.  
  179.  lastbase = base;
  180.  
  181.  if (base < 2)           {
  182.    if ( (exponent_entered) || (inkey == 54) )
  183.      signif_length = 19;
  184.    else
  185.      signif_length = 14; }
  186.  else
  187.    signif_length = display_length[ base ];
  188.  
  189.  if ( (next_digit >= signif_length) && (inkey != 53) ) {
  190.    BeepHpDisplay();
  191.    return( 0 );                     }
  192.  
  193.  if ((inkey == 50) && decimal_entered) {
  194.      BeepHpDisplay();
  195.      return(0);                        }
  196.  
  197.  if ( inkey == 50 ) decimal_entered = TRUE;
  198.  
  199.  if ( (inkey == 53) || (inkey == 54) )      {
  200.  
  201.     /*  CHS key has been struck      */
  202.     if ( inkey == 53 )                {
  203.       if ( exponent_entered )    {
  204.         flip_pos = 16;
  205.         flip_val = instring[16]; }
  206.       else                       {
  207.         flip_pos =  0;
  208.         flip_val = instring[ 0]; }
  209.       if ( flip_val == ' ' )
  210.         instring[ flip_pos ] = '-';
  211.       else
  212.         instring[ flip_pos ] = ' ';   }
  213.  
  214.     else    /* EEX entered */         {
  215.       exponent_entered = TRUE;
  216.       instring[17] = '_';   /* underscore as prompt */
  217.       next_digit   = 18;              }     }
  218.  
  219.  else   /*   A digit has been struck   */
  220.    instring[next_digit++] = digit_table[ inkey ];
  221.  
  222.  Move( rp, start_display[base], 59 );
  223.  Text( rp, &instring[0], next_digit);
  224.  
  225.  /*  Wipe out the exponent prompt character on the next keystroke */
  226.  if ( inkey == 54 ) next_digit = 17;
  227.  
  228. }
  229. /*--------------------------------------------------------*/
  230. CommenceNumEntry()
  231. {
  232.  int  k, str_offset;
  233.  lastbase = base;
  234.  
  235.  entry_in_progress  = TRUE;
  236.  
  237.  if ( inkey == 54 )
  238.    exponent_entered = TRUE;
  239.  else
  240.    exponent_entered = FALSE;
  241.  
  242.  if ( inkey == 50 )
  243.    decimal_entered  = TRUE;
  244.  else
  245.    decimal_entered = FALSE;
  246.  
  247.  if( base > 1 )
  248.    str_offset = 0;
  249.  else
  250.    str_offset = 8;
  251.  
  252.  /* Move x up to the y position */
  253.  Move( rp, start_display[base], 50);
  254.  Text( rp, &xstr[str_offset], display_length[base] );
  255.  
  256.  /* Blank out old x register */
  257.  Move( rp, start_display[base], 59 );
  258.  Text( rp, "                                ", display_length[base] );
  259.  
  260.  if ( base < 2 )    {
  261.    instring[0] = ' ';
  262.    for ( k = 2; k < 19; k++) instring[k] = ' ';
  263.  
  264.    if ( inkey == 54 )   {
  265.      instring[1] = '1';
  266.      instring[17] = '_';
  267.      next_digit = 18;
  268.                         }
  269.    else                 {
  270.      instring[ 1] = digit_table[ inkey ];
  271.      next_digit   = 2;  }  } 
  272.  else                {
  273.    instring[0]  = digit_table[ inkey ];
  274.    next_digit   = 1; }
  275.  
  276.  Move( rp, start_display[base], 59 );
  277.  Text( rp, &instring[0], next_digit);
  278.  
  279.  if ( inkey == 54 ) next_digit = 17;
  280.  
  281. }
  282. /*--------------------------------------------------------------*/
  283. PushX()
  284. {
  285.   int  k;
  286.  
  287.   if ( base > 1 ) {
  288.  
  289.      it = iz;
  290.      iz = iy;
  291.      iy = ix;
  292.  
  293.      ix = 0;
  294.      /*  Convert string to long integer       */     
  295.      for( k = 0; k < next_digit; k++)          {
  296.        if ( instring[k] > 60 ) instring[k] -= 7;
  297.        ix = base * ix + instring[k] - 48;      }
  298.      }
  299.  
  300.   else  {    /*  Push float or complex component onto stack */
  301.  
  302.     t = z;
  303.     z = y;
  304.     y = x;
  305.  
  306.     if ( instring[16] == ' ' )
  307.       instring[16] = 'e';
  308.     else
  309.       instring[15] = 'e';
  310.  
  311.     if ( instring[17] == '_' ) instring[17] = ' ';
  312.  
  313.     if ( decimal_entered == FALSE ) {
  314.       k = 1;
  315.       while ( (instring[k] != ' ') && (k < 14) )
  316.         k++;
  317.  
  318.       instring[k] = '.';    }
  319.     
  320.     for ( k = 1; k < 16; k++ )  {
  321.       if ( instring[k] == ' ' ) instring[k] = '0'; }
  322.  
  323.     instring[19] = 0;
  324.  
  325.     if  (instring[18] == ' ')   {
  326.        if (instring[17] == ' ')
  327.            instring[14] =   0;
  328.        else
  329.            instring[18] =   0;  }
  330.  
  331.     x = atof( &instring[0] );      }   
  332.  
  333.  
  334. }
  335.